package org.example.smartbuy.serviceImpl;

import org.example.smartbuy.entity.Inventory;
import org.example.smartbuy.entity.Productactions;
import org.example.smartbuy.mapper.InventoryMapper;
import org.example.smartbuy.service.IInventoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.smartbuy.service.IProductactionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Smarty Buy
 * @since 2024-11-18
 */
@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory> implements IInventoryService {

    @Autowired
    private InventoryMapper inventoryMapper;
    @Autowired
    private IProductactionsService productactionsService;

    @Override
    public List<Inventory> listAll() {
        return inventoryMapper.selectList(null);
    }

    @Override
    public Inventory add(Inventory inventory) {
        inventoryMapper.insert(inventory);
        return inventory;
    }

    @Override
    public Inventory update(Inventory inventory, int adminId) {
        inventoryMapper.updateById(inventory);
        //更新商品库存的操作记录
        Productactions productactions = new Productactions(null,adminId,inventory.getProductId(),"update",null,"更新商品库存:"+inventory.getQuantity());
        productactionsService.add(productactions);
        return inventory;
    }
}
